using System;
using MbUnit.Framework;
using DotNetNukeMVPWizard.ProjectConfiguration;

namespace DotNetNukeMVPWizard.Tests
{
    [TestFixture]
    public class TestUrlAddressConfiguration : EnvironmentalDependencies
    {
        private const string STR_KeyName = "KeyName";
        private const string STR_LocalUrlWithoutSchema = @"localhost/" + STR_DotNetNuke_Community;
        private const string STR_LocalUrlEndingInSpecificFileName = STR_LocalHost + STR_DotNetNuke_Community + "/default.aspx";
        private const string STR_BadLocalUrl = STR_LocalHost + @"Not/There/Either";
        private const string STR_NotARealUrl = @"http://BadUrl.Not.There";
        private const string STR_NotALocalUrl = @"http://www.Google.com";
        private IConfigurable Actual;

        [SetUp]
        public void SetUp()
        {
            Actual = new UrlAddressConfiguration(STR_KeyName);
        }

        #region Test Properties
        // TODO: Add test for UrlAddressConfiguration.ErrorMessage

        [Test]
        [Description("Ensure that setting value to null generates an empty string")]
        [Annotation(Gallio.Model.AnnotationType.Info, "Owner: Dan Gilleland")]
        public void FolderPathConfiguration_Set_Value_To_Null_Is_Transformed_To_Empty_String()
        {
            Actual.Value = null;
            Assert.AreEqual(string.Empty, Actual.Value);
        }

        [Test]
        [Description("Ensure that setting value to a path will ensure it has a trailing slash")]
        [Annotation(Gallio.Model.AnnotationType.Info, "Owner: Dan Gilleland")]
        public void FolderPathConfiguration_Set_Value_To_Path_Appends_Trailing_Slash()
        {
            Actual.Value = STR_GoodLocalUrl;
            Assert.AreEqual(STR_GoodLocalUrl + STR_TrailingUrlSlash, Actual.Value);
        }

        [Test]
        [Description("Ensure that setting value to a path will ensure it has a single trailing slash")]
        [Annotation(Gallio.Model.AnnotationType.Info, "Owner: Dan Gilleland")]
        public void FolderPathConfiguration_Set_Value_To_Path_Appends_Single_Trailing_Slash()
        {
            Actual.Value = STR_GoodLocalUrl + STR_TrailingUrlSlash;
            Assert.AreEqual(STR_GoodLocalUrl + STR_TrailingUrlSlash, Actual.Value);
        }

        [Test]
        [Timeout(60)]
        [Description("Ensure that IsValid is false for a non-optional empty string")]
        [Annotation(Gallio.Model.AnnotationType.Info, "Owner: Dan Gilleland")]
        public void UrlAddressConfiguration_Gets_IsValid_False_For_Empty_String()
        {
            Assert.IsFalse(Actual.IsValid);
        }

        [Test]
        [Timeout(60)]
        [Description("Ensure that IsValid is false for an URL that does not exist")]
        [Annotation(Gallio.Model.AnnotationType.Info, "Owner: Dan Gilleland")]
        public void UrlAddressConfiguration_Gets_IsValid_False_For_Non_Existing_Address()
        {
            Actual.Value = STR_NotARealUrl;
            Assert.IsFalse(Actual.IsValid);
        }

        [Test]
        [Timeout(60)]
        [Description("Ensure that IsValid is false for an URL that does not exist on LocalHost")]
        [Annotation(Gallio.Model.AnnotationType.Info, "Owner: Dan Gilleland")]
        public void UrlAddressConfiguration_Gets_IsValid_False_For_Bad_Local_Address()
        {
            Actual.Value = STR_BadLocalUrl;
            Assert.IsFalse(Actual.IsValid);
        }

        [Test]
        [Timeout(60)]
        [Description("Ensure that IsValid is false for an URL that exists but is not on the LocalHost")]
        [Annotation(Gallio.Model.AnnotationType.Info, "Owner: Dan Gilleland")]
        public void UrlAddressConfiguration_Gets_IsValid_False_For_Non_Local_Address()
        {
            Actual.Value = STR_NotALocalUrl;
            Assert.IsFalse(Actual.IsValid);
        }

        [Test]
        [Timeout(60)]
        [Description("Ensure that IsValid is false for an URL that exists on the LocalHost, but without a specified schema")]
        [Annotation(Gallio.Model.AnnotationType.Info, "Owner: Dan Gilleland")]
        public void UrlAddressConfiguration_Gets_IsValid_False_For_Local_Address_Without_Schema()
        {
            Actual.Value = STR_LocalUrlWithoutSchema;
            Assert.IsFalse(Actual.IsValid);
        }

        [Test]
        [Timeout(60)]
        [Description("Ensure that IsValid is false for an URL on the LocalHost that requests a specific file")]
        [Annotation(Gallio.Model.AnnotationType.Info, "Owner: Dan Gilleland")]
        public void UrlAddressConfiguration_Gets_IsValid_False_For_Local_Address_Ending_In_Specific_File_Name()
        {
            Actual.Value = STR_LocalUrlEndingInSpecificFileName;
            Assert.IsFalse(Actual.IsValid);
        }

        [Test]
        [Timeout(60)]
        [Description("Ensure that IsValid is false for an URL that is only the LocalHost (with no trailing segment)")]
        [Annotation(Gallio.Model.AnnotationType.Info, "Owner: Dan Gilleland")]
        public void UrlAddressConfiguration_Gets_IsValid_False_For_LocalHost_Only()
        {
            Actual.Value = STR_LocalHost;
            Assert.IsFalse(Actual.IsValid);
        }

        [Test]
        [Timeout(60)]
        [Description("Ensure that IsValid is false for a value that is a file address rather than an URL")]
        [Annotation(Gallio.Model.AnnotationType.Info, "Owner: Dan Gilleland")]
        public void UrlAddressConfiguration_Gets_IsValid_False_For_Valid_File_Address()
        {
            Actual.Value = @"C:\Windows";
            Assert.IsFalse(Actual.IsValid);
        }

        [Test]
        [Timeout(60)]
        [Description("Ensure that IsValid is true for an empty string when the URL is optional")]
        [Annotation(Gallio.Model.AnnotationType.Info, "Owner: Dan Gilleland")]
        public void UrlAddressConfiguration_Gets_IsValid_True_For_Optional_And_Empty_String()
        {
            Actual = new UrlAddressConfiguration(STR_KeyName, string.Empty, true);
            Assert.IsTrue(Actual.IsValid);
        }

        [Test]
        [Timeout(60)]
        [Description("Ensure that IsValid is true for a valid URL on the LocalHost")]
        [Annotation(Gallio.Model.AnnotationType.Info, "Owner: Dan Gilleland")]
        public void UrlAddressConfiguration_Gets_IsValid_True_For_ValidAddress()
        {
            Actual.Value = STR_GoodLocalUrl;
            Assert.IsTrue(Actual.IsValid);
        }
        #endregion
    }
}
